﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rodunu.Business.Models;
using Rodunu.Business.Models.Movies;
using Rodunu.Business.Models.ValueTypes;
using Rodunu.Services.IMDB;

namespace Rodunu.Clients.WPF
{
    public static class DataHelper
    {
        public static Title FillTitleWithOutOverwrite(Title serviceTitle, Title currentTitle)
        {
            //TODO: handle cast
            //TODO: handle countries
            //TODO: handle directors
            //TODO: handle file storage locations
            //TODO: handle genres
            //TODO: handle languages
            //TODO: handle tags
            if (currentTitle.Amazon.Length == 0)
                currentTitle.Amazon = serviceTitle.Amazon;
            if (currentTitle.Classification.Length == 0)
                currentTitle.Classification = serviceTitle.Classification;
            if (currentTitle.FileStorage.Color == Color.None)
                currentTitle.FileStorage.Color = serviceTitle.FileStorage.Color;
            if (currentTitle.FileStorage.Files == 0)
                currentTitle.FileStorage.Files = serviceTitle.FileStorage.Files;
            if (currentTitle.FileStorage.Region == Region.None)
                currentTitle.FileStorage.Region = serviceTitle.FileStorage.Region;
            if (currentTitle.FileStorage.VideoCodec == VideoCodec.None)
                currentTitle.FileStorage.VideoCodec = serviceTitle.FileStorage.VideoCodec;
            if (currentTitle.Id == 0)
                currentTitle.Id = serviceTitle.Id;
            if (currentTitle.ImageUrl.Length == 0)
                currentTitle.ImageUrl = serviceTitle.ImageUrl;
            if (currentTitle.IMDB.Length == 0)
                currentTitle.IMDB = serviceTitle.IMDB;
            if (currentTitle.MediaStorage.Collection.Length == 0)
                currentTitle.MediaStorage.Collection = serviceTitle.MediaStorage.Collection;
            if (currentTitle.MediaStorage.Condition == Condition.None)
                currentTitle.MediaStorage.Condition = serviceTitle.MediaStorage.Condition;
            if (currentTitle.MediaStorage.Discs == 0)
                currentTitle.MediaStorage.Discs = serviceTitle.MediaStorage.Discs;
            if (currentTitle.MediaStorage.Layers == Layers.None)
                currentTitle.MediaStorage.Layers = serviceTitle.MediaStorage.Layers;
            if (currentTitle.MediaStorage.Medium == Medium.None)
                currentTitle.MediaStorage.Medium = serviceTitle.MediaStorage.Medium;
            if (currentTitle.MediaStorage.Volume.Length == 0)
                currentTitle.MediaStorage.Volume = serviceTitle.MediaStorage.Volume;
            if (currentTitle.MPAARating.Length == 0)
                currentTitle.MPAARating = serviceTitle.MPAARating;
            if (currentTitle.Name.Length == 0)
                currentTitle.Name = serviceTitle.Name;
            if (currentTitle.Notes.Length == 0)
                currentTitle.Notes = serviceTitle.Notes;
            if (currentTitle.OfficialSite.Length == 0)
                currentTitle.OfficialSite = serviceTitle.OfficialSite;
            if (currentTitle.OriginalName.Length == 0)
                currentTitle.OriginalName = serviceTitle.OriginalName;
            if (currentTitle.Plot.Length == 0)
                currentTitle.Plot = serviceTitle.Plot;
            if (currentTitle.Rating == 0)
                currentTitle.Rating = serviceTitle.Rating;
            if (currentTitle.ReleaseDate.Length == 0)
                currentTitle.ReleaseDate = serviceTitle.ReleaseDate;
            if (currentTitle.Runtime == new DecimalWithUnits())
                currentTitle.Runtime = serviceTitle.Runtime;
            if (currentTitle.SeenIt == false)
                currentTitle.SeenIt = serviceTitle.SeenIt;
            if (currentTitle.Studio.Length == 0)
                currentTitle.Studio = serviceTitle.Studio;
            if (currentTitle.TagLine.Length == 0)
                currentTitle.TagLine = serviceTitle.TagLine;
            if (currentTitle.Year == 0)
                currentTitle.Year = serviceTitle.Year;

            return currentTitle;
        }

        public static IList<Title> ConvertSearchResultToTitles(IList<SearchResult> searchResults)
        {
            IList<Title> titles = new List<Title>();
            foreach (var searchResult in searchResults)
            {
                Title title = new Title();
                title.Name = searchResult.Name;
                title.Id = Convert.ToInt32(searchResult.Id);
                title.ImageUrl = searchResult.ImageUrl;
                titles.Add(title);
            }
            return titles;
        }
    }
}
